package com.xinqi.modules.prepare.video.convert;

import com.xinqi.common.mapstruct.CommonConvertConfig;
import com.xinqi.modules.prepare.common.dto.data.PrepareVideoData;
import com.xinqi.modules.prepare.video.domain.PrepareVideoPointEntity;
import com.xinqi.modules.prepare.video.dto.req.PrepareVideoCreateDTO;
import com.xinqi.modules.prepare.video.dto.req.PrepareVideoPointCreateDTO;
import com.xinqi.modules.prepare.video.dto.req.PrepareVideoPointUpdateDTO;
import com.xinqi.modules.prepare.video.dto.req.PrepareVideoUpdateDTO;
import com.xinqi.modules.prepare.video.dto.rsp.PrepareVideoPointResultDTO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.MappingTarget;

/**
 * 备课区互动视频环节转换
 *
 * @author: system
 * @date: 2023/03/19
 */
@Mapper(config = CommonConvertConfig.class)
public abstract class PrepareVideoPointConvert {
    @Mapping(target = "questionContent", expression = "java(com.xinqi.common.base.utils.json.JSON.stringify(s.getQuestionContent()))")
    @Mapping(target = "files", expression = "java(com.xinqi.common.base.utils.json.JSON.stringify(s.getFiles()))")
    public abstract PrepareVideoPointEntity create(PrepareVideoPointCreateDTO s);

    public abstract PrepareVideoPointCreateDTO create(PrepareVideoData.PrepareVideoPointData data);

    @Mapping(target = "questionContent", expression = "java(com.xinqi.common.base.utils.json.JSON.stringify(s.getQuestionContent()))")
    @Mapping(target = "files", expression = "java(com.xinqi.common.base.utils.json.JSON.stringify(s.getFiles()))")
    public abstract PrepareVideoPointEntity update(PrepareVideoPointUpdateDTO s, @MappingTarget PrepareVideoPointEntity t);

    @Mapping(target = "questionContent", expression = "java(com.xinqi.common.base.utils.json.JSON.stringify(s.getQuestionContent()))")
    @Mapping(target = "files", expression = "java(com.xinqi.common.base.utils.json.JSON.stringify(s.getFiles()))")
    public abstract PrepareVideoPointEntity update(PrepareVideoPointUpdateDTO s);

    @Mapping(target = "questionContent", expression = "java(com.xinqi.common.base.utils.json.JSON.parseList(s.getQuestionContent(), com.xinqi.common.base.dto.QuestionBaseDTO.class))")
    @Mapping(target = "files", expression = "java(com.xinqi.common.base.utils.json.JSON.parseList(s.getFiles(), com.xinqi.common.base.dto.CommonFileDTO.class))")
    public abstract PrepareVideoPointResultDTO convert(PrepareVideoPointEntity s);

    @Mapping(target = "id", ignore = true)
    @Mapping(target = "prepareId", ignore = true)
    @Mapping(target = "createBy", ignore = true)
    @Mapping(target = "createTime", ignore = true)
    @Mapping(target = "updateBy", ignore = true)
    @Mapping(target = "updateTime", ignore = true)
    public abstract PrepareVideoPointEntity copy(PrepareVideoPointEntity s, @MappingTarget PrepareVideoPointEntity t);

    public abstract PrepareVideoCreateDTO updateToCreate(PrepareVideoUpdateDTO dto);

}
